<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Exercise 4.38(b): Linear matrix inequalities with one variable</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/cvxbook/Ch04_cvx_opt_probs/html/ex_4_38.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Exercise 4.38(b): Linear matrix inequalities with one variable</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% From Boyd &amp; Vandenberghe, "Convex Optimization"</span>
<span class="comment">% Jo&euml;lle Skaf - 09/26/05</span>
<span class="comment">%</span>
<span class="comment">% Finds the optimal t that would maximize c*t while still having A - t*B</span>
<span class="comment">% positive semidefinite by solving the following SDP:</span>
<span class="comment">%           minimize    c*t</span>
<span class="comment">%               s.t.    t*B &lt;= A</span>
<span class="comment">% c can either be a positive or negative real number</span>

<span class="comment">% Generate input data</span>
randn(<span class="string">'state'</span>,0);
n = 4;
A = randn(n); A = 0.5*(A'+A); <span class="comment">%A = A'*A;</span>
B = randn(n); B = B'*B;
<span class="comment">% can modify the value of c (&gt;0 or &lt;0)</span>
c = -1;

<span class="comment">% Create and solve the model</span>
cvx_begin <span class="string">sdp</span>
    variable <span class="string">t</span>
    minimize ( c*t )
    A &gt;= t * B;
cvx_end

<span class="comment">% Display results</span>
disp(<span class="string">'------------------------------------------------------------------------'</span>);
disp(<span class="string">'The optimal t obtained is'</span>);
disp(t);
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling Mosek 9.1.9: 10 variables, 1 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:32:15)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 1               
  Cones                  : 0               
  Scalar variables       : 0               
  Matrix variables       : 1               
  Integer variables      : 0               

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 2                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.00    
Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 1               
  Cones                  : 0               
  Scalar variables       : 0               
  Matrix variables       : 1               
  Integer variables      : 0               

Optimizer  - threads                : 8               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 1
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 0                 conic                  : 0               
Optimizer  - Semi-definite variables: 1                 scalarized             : 10              
Factor     - setup time             : 0.00              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 1                 after factor           : 1               
Factor     - dense dim.             : 0                 flops                  : 4.60e+02        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   2.7e+00  1.4e+00  2.2e+00  0.00e+00   1.219269963e+00   0.000000000e+00   1.0e+00  0.00  
1   3.3e-01  1.8e-01  4.8e-01  -7.50e-01  -2.576084821e+00  -5.931855625e-01  1.2e-01  0.01  
2   4.6e-02  2.5e-02  1.5e-01  -5.70e-01  -1.761476200e+01  -3.964947856e+00  1.7e-02  0.01  
3   3.8e-03  2.1e-03  2.7e-02  -7.63e-01  -9.737046770e+01  -2.654953039e+01  1.4e-03  0.01  
4   3.6e-04  1.9e-04  9.2e-04  3.13e-01   -5.883568002e+01  -4.942827837e+01  1.3e-04  0.01  
5   6.3e-06  3.4e-06  1.5e-06  1.09e+00   -4.847665768e+01  -4.839880108e+01  2.4e-06  0.01  
6   1.4e-08  7.6e-09  1.6e-10  1.00e+00   -4.831917654e+01  -4.831900204e+01  5.3e-09  0.01  
7   1.8e-09  1.0e-09  6.8e-12  1.00e+00   -4.831899541e+01  -4.831897371e+01  6.6e-10  0.01  
8   1.1e-10  3.9e-09  1.1e-13  1.00e+00   -4.831898380e+01  -4.831898242e+01  4.2e-11  0.01  
9   2.1e-12  1.7e-08  2.7e-16  1.00e+00   -4.831898330e+01  -4.831898328e+01  7.7e-13  0.01  
Optimizer terminated. Time: 0.02    


Interior-point solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: -4.8318983303e+01   nrm: 7e+01    Viol.  con: 3e-10    barvar: 0e+00  
  Dual.    obj: -4.8318983278e+01   nrm: 3e+02    Viol.  con: 0e+00    barvar: 1e-10  
Optimizer summary
  Optimizer                 -                        time: 0.02    
    Interior-point          - iterations : 9         time: 0.01    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +48.354
 
------------------------------------------------------------------------
The optimal t obtained is
  -48.3540

</pre>
</div>
</body>
</html>